package contestseeker.visitors;

import org.htmlparser.Tag;
import org.htmlparser.tags.TableHeader;
import org.htmlparser.tags.TableRow;
import org.htmlparser.tags.TableTag;

public class BNU extends VisitorBase {
	public static final String NAME = "BNU";
	public static final String URL = "http://acm.cist.bnu.edu.cn/contest/contest_list.php";
	public static final String ENCODING = "UTF-8";
	public static final String TITLE = "BNU Online Judge Contests";

	public BNU() {
		super.URL = URL;
		super.ENCODING = ENCODING;
		super.TITLE = TITLE;
		super.NAME = NAME;
	}
	
	@Override
	public void visitTag(Tag tag)
	{
		if (tag instanceof TableTag)
		{
			TableTag table = (TableTag)tag;
			if (table.getAttribute("class") != null && table.getAttribute("class").compareTo("clist") == 0)
			{
				this.beginTable(TITLE);
				this.addHeader(table.getRow(0));
				TableRow row;
				TableHeader[] columns;
				for (int i = 1; i < table.getRowCount(); ++i)
				{
					row = table.getRow(i);
					columns = row.getHeaders();
					if (columns.length == 6 
							&& (columns[5].toPlainTextString().compareTo(" Running ") == 0 || columns[5].toPlainTextString().compareTo(" Scheduled ") == 0))
						this.addColumns(row);
				}
				this.endTable();
			}
		}
	}

}
